<%@ WebHandler Language="C#" Class="GetCostAccounting" %>
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MySql.Data.MySqlClient;
using LdExpress;

public class GetCostAccounting : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        string stcostno = "";
        if ((context.Request.QueryString.Get("costno") != "") && (context.Request.QueryString.Get("costno") != null))
        {
            stcostno = context.Request.QueryString.Get("costno");
        }
        string stVal = "";
        string sqlCommand = "";

        CustomerOfferPrices obj = new CustomerOfferPrices();
        DataSet ds = null;
        obj.DoSearch(" AND CostNumber= '" + stcostno+"'", "", out ds, GV.cn, GV.trans);
        if (ds.Tables[0].Rows.Count > 0)
        {
            CustomerRelation cust = new CustomerRelation();
            cust.ID = long.Parse(ds.Tables[0].Rows[0]["CustRelID"].ToString());
            cust.Load(GV.cn, GV.trans);
            //Get Username and Province
            string sql = "SELECT tbl_adminusers.UserName,tbl_tinh.Ten FROM tbl_adminusers,tbl_tinh WHERE " +
            "tbl_adminusers.IDProvince=tbl_tinh.ID AND tbl_adminusers.ID=" + ds.Tables[0].Rows[0]["UserID"].ToString();
            DataSet dsAdmin = DBModule.ExecuteQuery(sql, GV.cn, GV.trans);
            string SaleName = "";
            string SaleOfProvince = "";
            if (dsAdmin.Tables[0].Rows.Count > 0)
            {
                SaleName = dsAdmin.Tables[0].Rows[0]["Username"].ToString();
                SaleOfProvince = dsAdmin.Tables[0].Rows[0]["Ten"].ToString();
            }
            stVal = "{" +
            "\"POL\":" +
            "\"" + ds.Tables[0].Rows[0]["POL"].ToString() + "\"," +
            "\"POD\":" +
            "\"" + ds.Tables[0].Rows[0]["POD"].ToString() + "\"," +
            "\"Agent\":" +
            "\"" + ds.Tables[0].Rows[0]["Agent"].ToString() + "\"," +
            "\"Customer\":" +
            "\"" + cust.Name.ToString() + "\"," +
            "\"Liabilities\":" +
            "\"" + cust.CusLevel_Liabilities.ToString() + "\"," +
            "\"TB_Customer\":" +
            "\"" + cust.CusLevel_TB.ToString() + "\"," +
            "\"SaleName\":" +
            "\"" + SaleName + "\"," +
            "\"SaleOfProvince\":" +
            "\"" + SaleOfProvince + "\"," +
            "\"ETD\":" +
            "\"" + ds.Tables[0].Rows[0]["CostEtd"].ToString() + "\"," +
            "\"CarrSale\":" +
            "\"" + ds.Tables[0].Rows[0]["CarrierSale"].ToString() + "\"," +
            "\"CustPic\":" +
            "\"" + ds.Tables[0].Rows[0]["CustPic"].ToString() + "\"," +
            "\"OfferPriceID\":" +
            "\"" + ds.Tables[0].Rows[0]["ID"].ToString() + "\"" +
            "}";
        }
        context.Response.Write(stVal);
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}